<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for vue-test-utils-getting-started/coverage/lcov-report/sorter.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="..\..\..\prettify.css" />
    <link rel="stylesheet" href="..\..\..\base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(..\..\..\sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="..\..\..\index.html">All files</a> / <a href="index.html">vue-test-utils-getting-started/coverage/lcov-report</a> sorter.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/77</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/22</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/17</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/77</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">var addSorting = (function () <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >{</span></span>
    "use strict";
    var cols,
        currentS<span class="cstat-no" title="statement not covered" >ort = {</span>
            index: 0,
            desc: false
        };
&nbsp;
    // returns the summary table element
    functio<span class="fstat-no" title="function not covered" >n getTabl</span>e()<span class="cstat-no" title="statement not covered" > { return document.querySelector('.coverage-summary'</span>); }
    // returns the thead element of the summary table
    functio<span class="fstat-no" title="function not covered" >n getTableHeade</span>r()<span class="cstat-no" title="statement not covered" > { return getTable().querySelector('thead tr'</span>); }
    // returns the tbody element of the summary table
    functio<span class="fstat-no" title="function not covered" >n getTableBod</span>y()<span class="cstat-no" title="statement not covered" > { return getTable().querySelector('tbody'</span>); }
    // returns the th element for nth column
    functio<span class="fstat-no" title="function not covered" >n getNthColum</span>n(n)<span class="cstat-no" title="statement not covered" > { return getTableHeader().querySelectorAll('th')[n</span>]; }
&nbsp;
    // loads all columns
    functio<span class="fstat-no" title="function not covered" >n loadColumn</span>s() {
        var colNode<span class="cstat-no" title="statement not covered" >s = getTableHeader().querySelectorAll('t</span>h'),
            colNode,
<span class="cstat-no" title="statement not covered" >            co</span>ls = [],
            col,
            i;
&nbsp;
<span class="cstat-no" title="statement not covered" >        for (i = 0; i &lt; colNodes.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            colNode = colNode</span>s[i];
<span class="cstat-no" title="statement not covered" >            col = {</span>
                key: colNode.getAttribute('data-col'),
                sortable: !colNode.getAttribute('data-nosort'),
                type: colNode.getAttribute('data-type') || 'string'
            };
<span class="cstat-no" title="statement not covered" >            cols.push(</span>col);
<span class="cstat-no" title="statement not covered" >            if (col.sortable) {</span>
<span class="cstat-no" title="statement not covered" >                col.defaultDescSort = col.type === 'n</span>umber';
<span class="cstat-no" title="statement not covered" >                colNode.innerHTML = colNode.innerHTML + '&lt;span class="sorter"&gt;&lt;/</span>span&gt;';
            }
        }
<span class="cstat-no" title="statement not covered" >        return co</span>ls;
    }
    // attaches a data attribute to every tr element with an object
    // of data values keyed by column name
    functio<span class="fstat-no" title="function not covered" >n loadRowDat</span>a(tableRow) {
        var tableCol<span class="cstat-no" title="statement not covered" >s = tableRow.querySelectorAll('t</span>d'),
            colNode,
            col,
<span class="cstat-no" title="statement not covered" >            da</span>ta = {},
            i,
            val;
<span class="cstat-no" title="statement not covered" >        for (i = 0; i &lt; tableCols.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            colNode = tableCol</span>s[i];
<span class="cstat-no" title="statement not covered" >            col = col</span>s[i];
<span class="cstat-no" title="statement not covered" >            val = colNode.getAttribute('data-val</span>ue');
<span class="cstat-no" title="statement not covered" >            if (col.type === 'number') {</span>
<span class="cstat-no" title="statement not covered" >                val = Numbe</span>r(val);
            }
<span class="cstat-no" title="statement not covered" >            data[col.key] =</span> val;
        }
<span class="cstat-no" title="statement not covered" >        return da</span>ta;
    }
    // loads all row data
    functio<span class="fstat-no" title="function not covered" >n loadDat</span>a() {
        var row<span class="cstat-no" title="statement not covered" >s = getTableBody().querySelectorAll('t</span>r'),
            i;
&nbsp;
<span class="cstat-no" title="statement not covered" >        for (i = 0; i &lt; rows.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            rows[i].data = loadRowData(rows</span>[i]);
        }
    }
    // sorts the table using the data for the ith column
    functio<span class="fstat-no" title="function not covered" >n sortByInde</span>x(index, desc) {
        var ke<span class="cstat-no" title="statement not covered" >y = cols[index].</span>key,
            s<span class="cstat-no" title="statement not covered" >orter = f<span class="fstat-no" title="function not covered" >unction</span> (a, b) {</span>
<span class="cstat-no" title="statement not covered" >                a = a.d</span>ata[key];
<span class="cstat-no" title="statement not covered" >                b = b.d</span>ata[key];
<span class="cstat-no" title="statement not covered" >                return a &lt; b ? -1 : a &gt; b</span> ? 1 : 0;
            },
            finalS<span class="cstat-no" title="statement not covered" >orter =</span> sorter,
            tabl<span class="cstat-no" title="statement not covered" >eBody = document.querySelector('.coverage-summary </span>tbody'),
            row<span class="cstat-no" title="statement not covered" >Nodes = tableBody.querySelectorAl</span>l('tr'),
<span class="cstat-no" title="statement not covered" >            ro</span>ws = [],
            i;
&nbsp;
<span class="cstat-no" title="statement not covered" >        if (desc) {</span>
<span class="cstat-no" title="statement not covered" >            finalSorter = fun<span class="fstat-no" title="function not covered" >ction (a, b)</span> {</span>
<span class="cstat-no" title="statement not covered" >                return -1 * sorter</span>(a, b);
            };
        }
&nbsp;
<span class="cstat-no" title="statement not covered" >        for (i = 0; i &lt; rowNodes.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            rows.push(rowNodes</span>[i]);
<span class="cstat-no" title="statement not covered" >            tableBody.removeChild(rowNodes</span>[i]);
        }
&nbsp;
<span class="cstat-no" title="statement not covered" >        rows.sort(finalSorte</span>r);
&nbsp;
<span class="cstat-no" title="statement not covered" >        for (i = 0; i &lt; rows.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            tableBody.appendChild(rows</span>[i]);
        }
    }
    // removes sort indicators for current column being sorted
    functio<span class="fstat-no" title="function not covered" >n removeSortIndicator</span>s() {
        var co<span class="cstat-no" title="statement not covered" >l = getNthColumn(currentSort.ind</span>ex),
<span class="cstat-no" title="statement not covered" >            cls = col.cl</span>assName;
&nbsp;
<span class="cstat-no" title="statement not covered" >        cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '</span>');
<span class="cstat-no" title="statement not covered" >        col.className = c</span>ls;
    }
    // adds sort indicators for current column being sorted
    functio<span class="fstat-no" title="function not covered" >n addSortIndicator</span>s() {
<span class="cstat-no" title="statement not covered" >        getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorte</span>d';
    }
    // adds event listeners for all sorter widgets
    functio<span class="fstat-no" title="function not covered" >n enableU</span>I() {
        var i,
            el,
            ithS<span class="cstat-no" title="statement not covered" >orter = f<span class="fstat-no" title="function not covered" >unction it</span>hSorter(i) {</span>
<span class="cstat-no" title="statement not covered" >                var col </span>= cols[i];
&nbsp;
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ></span>                return function () {</span>
<span class="cstat-no" title="statement not covered" >                    var desc = col.defa</span>ultDescSort;
&nbsp;
<span class="cstat-no" title="statement not covered" >                    if (currentSort.index === i) {</span>
<span class="cstat-no" title="statement not covered" >                        desc = !curr</span>entSort.desc;
                    }
<span class="cstat-no" title="statement not covered" >                    sortByInde</span>x(i, desc);
<span class="cstat-no" title="statement not covered" >                    removeSortIn</span>dicators();
<span class="cstat-no" title="statement not covered" >                    currentSort</span>.index = i;
<span class="cstat-no" title="statement not covered" >                    currentSort.d</span>esc = desc;
<span class="cstat-no" title="statement not covered" >                    addSortIn</span>dicators();
                };
            };
<span class="cstat-no" title="statement not covered" >        for (i =0 ; i &lt; cols.length; i += 1) {</span>
<span class="cstat-no" title="statement not covered" >            if (cols[i].sortable) {</span>
                // add the click event handler on the th so users
                // dont have to click on those tiny arrows
<span class="cstat-no" title="statement not covered" >                el = getNthColumn(i).querySelector('.sorter').parentE</span>lement;
<span class="cstat-no" title="statement not covered" >                if (el.addEventListener) {</span>
<span class="cstat-no" title="statement not covered" >                    el.addEventListener('click', ithSo</span>rter(i));
                } else {
<span class="cstat-no" title="statement not covered" >                    el.attachEvent('onclick', ithSo</span>rter(i));
                }
            }
        }
    }
    // adds sorting functionality to the UI
<span class="cstat-no" title="statement not covered" >    retur<span class="fstat-no" title="function not covered" >n </span>function () {</span>
<span class="cstat-no" title="statement not covered" >        if (!getTable()) {</span>
<span class="cstat-no" title="statement not covered" >            re</span>turn;
        }
<span class="cstat-no" title="statement not covered" >        cols = loadColumns</span>();
<span class="cstat-no" title="statement not covered" >        loadData(col</span>s);
<span class="cstat-no" title="statement not covered" >        addSortIndicators</span>();
<span class="cstat-no" title="statement not covered" >        enableUI</span>();
    };
})();
&nbsp;
<span class="cstat-no" title="statement not covered" >window.addEventListener('load', addSorting);</span>
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Dec 16 2019 16:23:09 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="..\..\..\prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="..\..\..\sorter.js"></script>
</body>
</html>
